/*-------------------------*-
-*-------------------------*/

/*-------------------------*-
AddPlayerClass(265,1173.2454,1349.7618,10.9219,183.0055,0,0,0,0,0,0); // BIKE
AddPlayerClass(265,414.3472,2533.2781,19.1484,284.6103,0,0,0,0,0,0); // PLANE
AddPlayerClass(265,-2185.9133,2415.8989,5.1707,59.6889,0,0,0,0,0,0); // BOAT
AddPlayerClass(265,-2032.2019,-117.2515,1035.1719,89.5930,0,0,0,0,0,0); // CAR
-*-------------------------*/

#define VTYPE_CAR 		1
#define VTYPE_HEAVY 	2
#define VTYPE_BIKE 		3
#define VTYPE_AIR 		4
#define VTYPE_SEA 		5
#define VTYPE_MISC 		6
#define VTYPE_MOTORBIKE 7

#include <a_samp>

#define SCHOOL_CHECKPOINT_SIZE (5.0)

new const Float:gSchool_Checkpoints[4][15][4] = //480byte
{
	{ // car
		{-2044.831665, -84.298553, 34.891147, SCHOOL_CHECKPOINT_SIZE},
		{-2062.551025, -67.523361, 34.171875, SCHOOL_CHECKPOINT_SIZE},
		{-2184.348389, -183.642639, 34.179665, SCHOOL_CHECKPOINT_SIZE},
		{-2363.787842, -176.403320, 34.171875, SCHOOL_CHECKPOINT_SIZE},
		{-2418.666992, -56.608231, 34.171875, SCHOOL_CHECKPOINT_SIZE},
		{-2413.508789, 245.954803, 34.015625, SCHOOL_CHECKPOINT_SIZE},
		{-2320.937012, 435.662628, 33.713043, SCHOOL_CHECKPOINT_SIZE},
		{-2368.101807, 562.243774, 23.742188, SCHOOL_CHECKPOINT_SIZE},
		{-1986.924561, 602.606873, 34.015625, SCHOOL_CHECKPOINT_SIZE},
		{-1901.153931, 582.355713, 33.879448, SCHOOL_CHECKPOINT_SIZE},
		{-1842.952393, 377.346558, 16.180994, SCHOOL_CHECKPOINT_SIZE},
		{-1924.186646, -193.792511, 37.193665, SCHOOL_CHECKPOINT_SIZE},
		{-2020.514404, -312.366516, 34.299076, SCHOOL_CHECKPOINT_SIZE},
		{-2023.426025, -67.786690, 34.171875, SCHOOL_CHECKPOINT_SIZE},
		{-2047.256104, -85.511429, 34.164063, SCHOOL_CHECKPOINT_SIZE}
	},

	{ // bike
		{1171.262451, 1370.219848, 10.391620, SCHOOL_CHECKPOINT_SIZE},
		{1006.916320, 1528.514282, 10.240498, SCHOOL_CHECKPOINT_SIZE},
		{1030.855590, 1952.846313, 10.237700, SCHOOL_CHECKPOINT_SIZE},
		{1121.523925, 2052.795898, 10.237578, SCHOOL_CHECKPOINT_SIZE},
		{1524.717773, 2058.253906, 10.362090, SCHOOL_CHECKPOINT_SIZE},
		{1670.386962, 2273.056884, 10.237950, SCHOOL_CHECKPOINT_SIZE},
		{2108.463623, 2281.128417, 10.244203, SCHOOL_CHECKPOINT_SIZE},
		{2032.472290, 1713.313110, 10.235921, SCHOOL_CHECKPOINT_SIZE},
		{1788.867553, 1420.220703, 6.307698, SCHOOL_CHECKPOINT_SIZE},
		{1789.417114, 863.941284, 10.212225, SCHOOL_CHECKPOINT_SIZE},
		{1415.558837, 849.307739, 6.378320, SCHOOL_CHECKPOINT_SIZE},
		{1218.364379, 1265.752075, 6.277549, SCHOOL_CHECKPOINT_SIZE},
		{1175.613891, 1371.301757, 10.388628, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE}
	},

	{ // boat
		{-2146.997558, 2428.942138, -0.089766, SCHOOL_CHECKPOINT_SIZE},
		{-1988.861694, 2160.382324, 0.229864, SCHOOL_CHECKPOINT_SIZE},
		{-1532.871215, 1526.836059, -0.008878, SCHOOL_CHECKPOINT_SIZE},
		{-1528.641723, 1344.618164, -0.133019, SCHOOL_CHECKPOINT_SIZE},
		{-2233.000000, 1549.306152, -0.206533, SCHOOL_CHECKPOINT_SIZE},
		{-2654.497802, 1613.182250, -0.143991, SCHOOL_CHECKPOINT_SIZE},
		{-2939.801025, 1609.459228, 0.398771, SCHOOL_CHECKPOINT_SIZE},
		{-3045.286865, 2008.724365, 0.988168, SCHOOL_CHECKPOINT_SIZE},
		{-2684.370849, 2152.355224, -0.104622, SCHOOL_CHECKPOINT_SIZE},
		{-2214.705566, 2244.005126, 0.294517, SCHOOL_CHECKPOINT_SIZE},
		{-2237.232910, 2393.193115, -0.071032, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE}
	},

	{ // fly
		{383.262115, 2507.501708, 16.962657, SCHOOL_CHECKPOINT_SIZE},
		{71.122306, 2497.119873, 30.762842, SCHOOL_CHECKPOINT_SIZE},
		{-297.224090, 2420.688964, 87.799217, SCHOOL_CHECKPOINT_SIZE},
		{-355.184509, 2112.731445, 134.605667, SCHOOL_CHECKPOINT_SIZE},
		{-382.305267, 1588.746093, 90.777839, SCHOOL_CHECKPOINT_SIZE},
		{-50.976974, 1488.350341, 37.895282, SCHOOL_CHECKPOINT_SIZE},
		{-128.558074, 1821.145751, 57.653831, SCHOOL_CHECKPOINT_SIZE},
		{-267.346954, 1867.649414, 57.647132, SCHOOL_CHECKPOINT_SIZE},
		{-555.859252, 2447.520263, 104.659568, SCHOOL_CHECKPOINT_SIZE},
		{-183.767349, 2637.542480, 94.358642, SCHOOL_CHECKPOINT_SIZE},
		{211.729034, 2521.661132, 30.813814, SCHOOL_CHECKPOINT_SIZE},
		{424.360687, 2522.456298, 16.947921, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE},
		{0.0, 0.0, 0.0, SCHOOL_CHECKPOINT_SIZE}
	}
};

#define debugprint(%1,%2) SendClientMessage(%1,0x0000FF00,%2),print(%2)

#define COLOR_RED (0xFF0000FF)
#define COLOR_GREEN (0x009900FF)

#define SCHOOL_MAXIMUM_DAMAGE (100.0) // 10%

#define SCHOOL_CAR_POSX (-2032.2019)
#define SCHOOL_CAR_POSY (-117.2515)
#define SCHOOL_CAR_POSZ (1035.1719)
#define SCHOOL_FLY_POSX (414.3472)
#define SCHOOL_FLY_POSY (2533.2781)
#define SCHOOL_FLY_POSZ (19.1484)
#define SCHOOL_BOAT_POSX (-2185.9133)
#define SCHOOL_BOAT_POSY (2415.8989)
#define SCHOOL_BOAT_POSZ (5.1707)
#define SCHOOL_BIKE_POSX (1173.2454)
#define SCHOOL_BIKE_POSY (1349.7618)
#define SCHOOL_BIKE_POSZ (10.9219)

#define SCHOOL_PLAYER_FLAG_CHECKPOINT (1<<0+1<<1+1<<2+1<<3)
#define SCHOOL_PLAYER_FLAG_CARLICENSE (1<<4)
#define SCHOOL_PLAYER_FLAG_BIKELICENSE (1<<5)
#define SCHOOL_PLAYER_FLAG_FLYLICENSE (1<<6)
#define SCHOOL_PLAYER_FLAG_BOATLICENSE (1<<7)
#define SCHOOL_PLAYER_FLAG_CANCARLIC (1<<8)
#define SCHOOL_PLAYER_FLAG_CANBIKELIC (1<<9)
#define SCHOOL_PLAYER_FLAG_CANFLYLIC (1<<10)
#define SCHOOL_PLAYER_FLAG_CANBOATLIC (1<<11)
#define SCHOOL_PLAYER_FLAG_TEST (1<<12+1<<13+1<<14)
#define SCHOOL_PLAYER_FLAG_ATCARSCHOOL (1<<15)
#define SCHOOL_PLAYER_FLAG_ATBIKESCHOOL (1<<16)
#define SCHOOL_PLAYER_FLAG_ATFLYSCHOOL (1<<17)
#define SCHOOL_PLAYER_FLAG_ATBOATSCHOOL (1<<18)

#define SCHOOL_TEST_ID_NONE (0)
#define SCHOOL_TEST_ID_CAR (1)
#define SCHOOL_TEST_ID_BIKE (2)
#define SCHOOL_TEST_ID_FLY (3)
#define SCHOOL_TEST_ID_BOAT (4)

// -- TODO: Fill these times for each test (in tick)
#define SCHOOL_MAXTIME_CAR (0000)
#define SCHOOL_MAXTIME_BOAT (60000)
#define SCHOOL_MAXTIME_BIKE (60000)
#define SCHOOL_MAXTIME_FLY (60000)
#define SCHOOL_MINTIME_CAR (6000)
#define SCHOOL_MINTIME_BOAT (6000)
#define SCHOOL_MINTIME_BIKE (6000)
#define SCHOOL_MINTIME_FLY (6000)

#define VEHICLE_FLAG_FIRST (0x3FF)
#define VEHICLE_FLAG_SECOND (0xFFC01)
#define VEHICLE_FLAG_THIRD (0x3FF003FF)


#define Player_SetCheckpoint(%1,%2) (gSchool_PlayerCheckpoint[(%1)]=(%2))
#define Player_GetCheckpoint(%1) (gSchool_PlayerCheckpoint[(%1)])

#define Player_SetTestID(%1,%2) (gSchool_PlayerTest[(%1)]=(%2))
#define Player_GetTestID(%1) (gSchool_PlayerTest[(%1)])

// Total of 2100bytes allocated at the start
new Menu:g_pSchool_Menu = Menu:INVALID_MENU; //4byte
new gSchool_PlayerFlags[MAX_PLAYERS]; //800byte
new gSchool_PlayerTimes[MAX_PLAYERS]; //800byte
new gSchool_CheckpointAmounts[4];
new g_pSchool_Vehicles[4]; //16byte

new gSchool_PlayerCheckpoint[MAX_PLAYERS];
new gSchool_PlayerTest[MAX_PLAYERS];

//new Text:gSchool_PlayerTextDraw[MAX_PLAYERS];


forward School_Loop();


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
main()
{
	// -- TODO: Remove these 2 lines, if the script works properly
	SetGameModeText( "LICENSE SYSTEM 0.0.4" );
	AddPlayerClass( 102, -2050.0, -97.054222, 35.882465, 90.0, 0, 0, 0, 0, 0, 0 );

	for( new idx=0; idx<MAX_PLAYERS; idx++ ){
		gSchool_PlayerFlags[idx] = 0;
		gSchool_PlayerTimes[idx] = 0;
		gSchool_PlayerCheckpoint[idx] = 0;
		gSchool_PlayerTest[idx] = 0;
		//gSchool_PlayerTextDraw[idx] = Text:INVALID_TEXT_DRAW;
	}

	
/*
	new i=0;
	for( i=0; i<15 && gSchool_Checkpoints[0][i][0] != 0.0; i++ ) gSchool_CheckpointAmounts[0]++;
	for( i=0; i<15 && gSchool_Checkpoints[1][i][0] != 0.0; i++ ) gSchool_CheckpointAmounts[1]++;
	for( i=0; i<15 && gSchool_Checkpoints[2][i][0] != 0.0; i++ ) gSchool_CheckpointAmounts[3]++;
	for( i=0; i<15 && gSchool_Checkpoints[3][i][0] != 0.0; i++ ) gSchool_CheckpointAmounts[2]++;
*/
	gSchool_CheckpointAmounts[0] = 15;
	gSchool_CheckpointAmounts[1] = 13;
	gSchool_CheckpointAmounts[2] = 12;
	gSchool_CheckpointAmounts[3] = 11;
	
	// CAR blista compact
	g_pSchool_Vehicles[0] |= CreateVehicle( 496, -2050.0, -97.054222, 34.882465, 0.3, -1, -1, 10 ) & VEHICLE_FLAG_FIRST;
	g_pSchool_Vehicles[0] |= (CreateVehicle( 496, -2046.0, -97.054222, 34.883880, 0.3, -1, -1, 10 )<<10) & VEHICLE_FLAG_SECOND;
	g_pSchool_Vehicles[0] |= (CreateVehicle( 496, -2042.0, -97.054222, 34.880268, 0.3, -1, -1, 10 )<<20) & VEHICLE_FLAG_THIRD;

	// BOAT jetmax
	g_pSchool_Vehicles[1] |= CreateVehicle( 493, -2222.715576, 2398.058105, -0.099849, 39.568969, -1, -1, 10 ) & VEHICLE_FLAG_FIRST;
	g_pSchool_Vehicles[1] |= (CreateVehicle( 493, -2232.352539, 2393.290771, -0.116131, 39.568969, -1, -1, 10 )<<10) & VEHICLE_FLAG_SECOND;
	g_pSchool_Vehicles[1] |= (CreateVehicle( 493, -2209.502929, 2410.615234, -0.087562, 39.568969, -1, -1, 10 )<<20) & VEHICLE_FLAG_THIRD;

	// AIR dodo
	g_pSchool_Vehicles[2] |= CreateVehicle( 593, 352.946777, 2541.224609, 17.185791, 178.867675, -1, -1, 10 ) & VEHICLE_FLAG_FIRST;
	g_pSchool_Vehicles[2] |= (CreateVehicle( 593, 366.250122, 2540.902587, 17.067834, 179.798858, -1, -1, 10 )<<10) & VEHICLE_FLAG_SECOND;
	g_pSchool_Vehicles[2] |= (CreateVehicle( 593, 380.827667, 2540.940185, 16.998163, 180.541809, -1, -1, 10 )<<20) & VEHICLE_FLAG_THIRD;

	// BIKE pcj-600
	g_pSchool_Vehicles[3] |= CreateVehicle( 461, 1175.6, 1368.0, 10.393104, 87.313140, -1, -1, 10 ) & VEHICLE_FLAG_FIRST;
	g_pSchool_Vehicles[3] |= (CreateVehicle( 461, 1175.6, 1366.0, 10.381062, 89.579513, -1, -1, 10 )<<10) & VEHICLE_FLAG_SECOND;
	g_pSchool_Vehicles[3] |= (CreateVehicle( 461, 1175.6, 1370.0, 10.380723, 88.615119, -1, -1, 10 )<<20) & VEHICLE_FLAG_THIRD;

	g_pSchool_Menu = CreateMenu( "Welcome to the Test", 2, 200.0, 100.0, 150.0, 150.0 );
	AddMenuItem( g_pSchool_Menu, 0, "Take Test" );
	AddMenuItem( g_pSchool_Menu, 0, "Receive License" );
	
	SetTimer( "School_Loop", 1000, true );
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
public OnPlayerDisconnect( playerid, reason )
{
	gSchool_PlayerFlags[playerid] = 0;
	gSchool_PlayerTimes[playerid] = 0;
	gSchool_PlayerTest[playerid] = 0;
	gSchool_PlayerCheckpoint[playerid] = 0;

	/*if(	gSchool_PlayerTextDraw[playerid] != Text:INVALID_TEXT_DRAW )
	{
		TextDrawHideForPlayer( playerid, gSchool_PlayerTextDraw[playerid] );
		TextDrawDestroy( gSchool_PlayerTextDraw[playerid] );
		gSchool_PlayerTextDraw[playerid] = Text:INVALID_TEXT_DRAW;
	}*/
	return 1; 
}


stock bool:Player_IsInPointRange( playerid, Float:x, Float:y, Float:z, Float:r )
{
	new Float:X, Float:Y, Float:Z;
		
	GetPlayerPos( playerid, X, Y, Z );

	X -= x;
	Y -= y;
	Z -= z;
	
	return (( X * X + Y * Y + Z * Z ) < ( r * r ));
}


public OnPlayerStateChange( playerid, newstate, oldstate )
{
	if( oldstate == 2 && Player_GetTestID( playerid ) != SCHOOL_TEST_ID_NONE )
	{
		/*TextDrawHideForPlayer( playerid, gSchool_PlayerTextDraw[playerid] );
		TextDrawDestroy( gSchool_PlayerTextDraw[playerid] );
		gSchool_PlayerTextDraw[playerid] = Text:INVALID_TEXT_DRAW;*/

		DisablePlayerRaceCheckpoint( playerid );
		Player_SetCheckpoint( playerid, 0 );
		Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );

		SendClientMessage( playerid, COLOR_RED, "Test Failed: You left your vehicle!" );
	}
	
	if( Player_GetTestID( playerid ) == 0 && newstate == 2 )
	{
		if( NeedLicense( GetVehicleModel( GetPlayerVehicleID( playerid ) ) ) == 1 )
		{
			switch( GetVehicleType( GetPlayerVehicleID( playerid ) ) )
			{
				case VTYPE_CAR, VTYPE_HEAVY:
				{
					if( !(gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CARLICENSE) )
					{
						SendClientMessage( playerid, COLOR_RED, "You don't have a car license" );
						RemovePlayerFromVehicle( playerid );
					}
				}
				case VTYPE_MOTORBIKE:
				{
					if( !(gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_BIKELICENSE) )
					{
						SendClientMessage( playerid, COLOR_RED, "You don't have a bike license" );
						RemovePlayerFromVehicle( playerid );
					}
				}
				case VTYPE_AIR:
				{
					if( !(gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_FLYLICENSE) )
					{
						SendClientMessage( playerid, COLOR_RED, "You don't have a flying license" );
						RemovePlayerFromVehicle( playerid );
					}
				}
				case VTYPE_SEA:
				{
					if( !(gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_BOATLICENSE) )
					{
						SendClientMessage( playerid, COLOR_RED, "You don't have a boat license" );
						RemovePlayerFromVehicle( playerid );
					}
				}
			}
		}
	}
	return 1;
}

public School_Loop()
{
	for( new i=0; i<MAX_PLAYERS; i++ )
	{
		if( IsPlayerConnected( i ) && Player_GetTestID(i) == SCHOOL_TEST_ID_NONE )
		{
			// CAR
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_CARLICENSE) && Player_IsInPointRange( i, SCHOOL_CAR_POSX, SCHOOL_CAR_POSY, SCHOOL_CAR_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_CAR_POSX, SCHOOL_CAR_POSY, SCHOOL_CAR_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATCARSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATCARSCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// BIKE
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_BIKELICENSE) && Player_IsInPointRange( i, SCHOOL_BIKE_POSX, SCHOOL_BIKE_POSY, SCHOOL_BIKE_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_BIKE_POSX, SCHOOL_BIKE_POSY, SCHOOL_BIKE_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATBIKESCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATBIKESCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// AIR
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_FLYLICENSE) && Player_IsInPointRange( i, SCHOOL_FLY_POSX, SCHOOL_FLY_POSY, SCHOOL_FLY_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_FLY_POSX, SCHOOL_FLY_POSY, SCHOOL_FLY_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATFLYSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATFLYSCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// SEA
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_BOATLICENSE) && Player_IsInPointRange( i, SCHOOL_BOAT_POSX, SCHOOL_BOAT_POSY, SCHOOL_BOAT_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_BOAT_POSX, SCHOOL_BOAT_POSY, SCHOOL_BOAT_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATBOATSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATBOATSCHOOL;
				DisablePlayerCheckpoint( i );
			}
		}
		else if( IsPlayerConnected( i ) && Player_GetTestID(i) != SCHOOL_TEST_ID_NONE )
		{
			if( Player_GetCheckpoint( i ) >= 2 )
			{
				new ttime;
				switch( Player_GetTestID(i) )
				{
					case SCHOOL_TEST_ID_CAR: ttime = SCHOOL_MAXTIME_CAR-gSchool_PlayerTimes[i];
					case SCHOOL_TEST_ID_BIKE: ttime = SCHOOL_MAXTIME_BIKE-gSchool_PlayerTimes[i];
					case SCHOOL_TEST_ID_FLY: ttime = SCHOOL_MAXTIME_FLY-gSchool_PlayerTimes[i];
					case SCHOOL_TEST_ID_BOAT: ttime = SCHOOL_MAXTIME_BOAT-gSchool_PlayerTimes[i];
				} 
				
				if( ttime < 0 ) ttime = 0;
			
				new string[30];
				new second = ttime % 60;
				new minute = (ttime-second)/60;
				format( string, sizeof(string), " ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~~w~%02d:%02d", minute, second );
				GameTextForPlayer( i, string, 1100, 3 );
				//TextDrawSetString( gSchool_PlayerTextDraw[i], string );
				gSchool_PlayerTimes[i]++;
			}
		}
	}
}


public OnPlayerExitedMenu( playerid )
{
	TogglePlayerControllable( playerid, true );
	return 1;
}


public OnPlayerEnterRaceCheckpoint( playerid )
{
	new exam = Player_GetTestID( playerid );
	
	if( exam != SCHOOL_TEST_ID_NONE )
	{
		new check = Player_GetCheckpoint( playerid );
		new vehicleid = GetPlayerVehicleID( playerid );
		new Float:hp;

		GetVehicleHealth( vehicleid, hp );
		DisablePlayerRaceCheckpoint( playerid );

		if( hp <= (1000-SCHOOL_MAXIMUM_DAMAGE) )
		{
			/*TextDrawHideForPlayer( playerid, gSchool_PlayerTextDraw[playerid] );
			TextDrawDestroy( gSchool_PlayerTextDraw[playerid] );
			gSchool_PlayerTextDraw[playerid] = Text:INVALID_TEXT_DRAW;*/

			SendClientMessage( playerid, COLOR_RED, "Test Failed: You have damaged your vehicle!" );
			Player_SetCheckpoint( playerid, 0 );
			Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );
			RemovePlayerFromVehicle( playerid );
		}
		else
		{
			if( (check+1) <= gSchool_CheckpointAmounts[exam-1] )
			{
				if( check == 1 )
				{
					SendClientMessage( playerid, COLOR_RED, "IF YOU GET THIS MESSAGE, THE PROBLEM IS WITH THE TEXTDRAW" );
				
					gSchool_PlayerTimes[playerid] = 0;
					GameTextForPlayer( playerid, " ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~~r~TEST STARTED", 1100, 3 );
					/*gSchool_PlayerTextDraw[playerid] = TextDrawCreate( 543.0, 742.0, "~r~TEST STARTED" );
					TextDrawUseBox( gSchool_PlayerTextDraw[playerid], 0 );
					TextDrawFont( gSchool_PlayerTextDraw[playerid], 2 );
					TextDrawSetShadow( gSchool_PlayerTextDraw[playerid], 0 );
					TextDrawSetOutline( gSchool_PlayerTextDraw[playerid], 1 );
					TextDrawBackgroundColor( gSchool_PlayerTextDraw[playerid], 0x000000FF );
					TextDrawColor( gSchool_PlayerTextDraw[playerid], 0xFFFFFFFF );
					TextDrawAlignment( gSchool_PlayerTextDraw[playerid], 3 );
					TextDrawShowForPlayer( playerid, gSchool_PlayerTextDraw[playerid] );*/
				}
			
				check++;
				
				new type;
				if( exam == SCHOOL_TEST_ID_CAR ) type = 0;
				else if( exam == SCHOOL_TEST_ID_BIKE ) type = 1;
				else if( exam == SCHOOL_TEST_ID_FLY ) type = 3;
				else if( exam == SCHOOL_TEST_ID_BOAT ) type = 2;
				
				if( (check+1) == gSchool_CheckpointAmounts[exam-1] )
					SetPlayerRaceCheckpoint( playerid, exam==SCHOOL_TEST_ID_FLY ? 3 : 1, gSchool_Checkpoints[type][check][0], gSchool_Checkpoints[type][check][1], gSchool_Checkpoints[type][check][2], 0.0, 0.0, 0.0, gSchool_Checkpoints[type][check][3] );

				else
					SetPlayerRaceCheckpoint( playerid, exam==SCHOOL_TEST_ID_FLY ? 2 : 0, gSchool_Checkpoints[type][check][0], gSchool_Checkpoints[type][check][1], gSchool_Checkpoints[type][check][2], gSchool_Checkpoints[type][check+1][0], gSchool_Checkpoints[type][check+1][1], gSchool_Checkpoints[type][check+1][2], gSchool_Checkpoints[type][check][3] );

				Player_SetCheckpoint( playerid, check );
			}
			else
			{
				/*TextDrawHideForPlayer( playerid, gSchool_PlayerTextDraw[playerid] );
				TextDrawDestroy( gSchool_PlayerTextDraw[playerid] );
				gSchool_PlayerTextDraw[playerid] = Text:INVALID_TEXT_DRAW;*/
			
				vehicleid = 0;
				new time = gSchool_PlayerTimes[playerid];
				switch( exam )
				{
					case SCHOOL_TEST_ID_CAR:
					{
						if( time < SCHOOL_MAXTIME_CAR ) vehicleid = 1;
						else if( time > SCHOOL_MINTIME_CAR ) vehicleid = 2;
					}
					case SCHOOL_TEST_ID_FLY:
					{
						if( time < SCHOOL_MAXTIME_FLY ) vehicleid = 1;
						else if( time > SCHOOL_MINTIME_FLY ) vehicleid = 2;
					}
					case SCHOOL_TEST_ID_BIKE:
					{
						if( time < SCHOOL_MAXTIME_BIKE ) vehicleid = 1;
						else if( time > SCHOOL_MINTIME_BIKE ) vehicleid = 2;
					}
					case SCHOOL_TEST_ID_BOAT:
					{
						if( time < SCHOOL_MAXTIME_BOAT ) vehicleid = 1;
						else if( time > SCHOOL_MINTIME_BOAT ) vehicleid = 2;
					}
				}
				
				if( vehicleid == 1 )
				{
					gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_CANCARLIC << (exam-1);
					SendClientMessage( playerid, COLOR_GREEN, "Congratulations! Go and get your license at the school!" );
				}
				else if( vehicleid == 0 )
				{
					new str[64];
					new sec = time%60;
					new minute = (time-sec)/60;
					format( str, sizeof(str), "Test Failed: Out of time! (Your time: %02d:%02d)", time, minute );
					SendClientMessage( playerid, COLOR_RED, str );
				}
				else if( vehicleid == 2 )
				{
					SendClientMessage( playerid, COLOR_RED, "Test Failed: You were too fast!" );
				}
				Player_SetCheckpoint( playerid, 0 );
				Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );
				RemovePlayerFromVehicle( playerid );
			}
		}
	}
	return 1;
}

public OnPlayerEnterCheckpoint( playerid )
{
	if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL || gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL ||
		gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL || gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
	{
		ShowMenuForPlayer( g_pSchool_Menu, playerid );
		TogglePlayerControllable( playerid, false );
	}
	return 1;
}

stock Vehicle_GetDriver( vehicleid )
{
	for( new x=0; x<MAX_PLAYERS; x++ ) if( IsPlayerConnected(x) && GetPlayerVehicleID(x) == vehicleid && GetPlayerState(x) == 2 ) return x;
	return INVALID_PLAYER_ID;
}

public OnPlayerSelectedMenuRow( playerid, row )
{
	if( GetPlayerMenu( playerid ) == g_pSchool_Menu )
	{
		TogglePlayerControllable( playerid, true );

		switch( row )
		{
			case 0:
			{
				DisablePlayerCheckpoint( playerid );
					
				if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL )
				{
					new vehicleid;
					vehicleid = g_pSchool_Vehicles[1] & VEHICLE_FLAG_FIRST;
					if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
					{
						vehicleid = (g_pSchool_Vehicles[1] & VEHICLE_FLAG_SECOND)>>10;
						if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
						{
							vehicleid = (g_pSchool_Vehicles[1] & VEHICLE_FLAG_THIRD)>>20;
							if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
								SendClientMessage( playerid, COLOR_RED, "Sorry, all of our boats are in use." );
						}
					}
					else
					{
						SetPlayerInterior( playerid, 0 );
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						//SetVehiclePos( vehicleid, gSchool_Checkpoints[2][0][0], gSchool_Checkpoints[2][0][1], gSchool_Checkpoints[2][0][2] );
						SetPlayerRaceCheckpoint( playerid, 0, gSchool_Checkpoints[2][1][0], gSchool_Checkpoints[2][1][1], gSchool_Checkpoints[2][1][2], gSchool_Checkpoints[2][2][0], gSchool_Checkpoints[2][2][1], gSchool_Checkpoints[2][2][2], gSchool_Checkpoints[2][1][3] );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_BOAT );
						gSchool_PlayerFlags[playerid] &= ~SCHOOL_PLAYER_FLAG_ATBOATSCHOOL;
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL )
				{
					new vehicleid;
					vehicleid = g_pSchool_Vehicles[2] & VEHICLE_FLAG_FIRST;
					if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
					{
						vehicleid = (g_pSchool_Vehicles[2] & VEHICLE_FLAG_SECOND)>>10;
						if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
						{
							vehicleid = (g_pSchool_Vehicles[2] & VEHICLE_FLAG_THIRD)>>20;
							if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
								SendClientMessage( playerid, COLOR_RED, "Sorry, all of our boats are in use." );
						}
					}
					else
					{
						SetPlayerInterior( playerid, 0 );
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						//SetVehiclePos( vehicleid, gSchool_Checkpoints[3][0][0], gSchool_Checkpoints[3][0][1], gSchool_Checkpoints[3][0][2] );
						SetPlayerRaceCheckpoint( playerid, 2, gSchool_Checkpoints[3][1][0], gSchool_Checkpoints[3][1][1], gSchool_Checkpoints[3][1][2], gSchool_Checkpoints[3][2][0], gSchool_Checkpoints[3][2][1], gSchool_Checkpoints[3][2][2], gSchool_Checkpoints[3][1][3] );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_FLY );
						gSchool_PlayerFlags[playerid] &= ~SCHOOL_PLAYER_FLAG_ATFLYSCHOOL;
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
				{
					new vehicleid;
					vehicleid = g_pSchool_Vehicles[0] & VEHICLE_FLAG_FIRST;
					if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
					{
						vehicleid = (g_pSchool_Vehicles[0] & VEHICLE_FLAG_SECOND)>>10;
						if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
						{
							vehicleid = (g_pSchool_Vehicles[0] & VEHICLE_FLAG_THIRD)>>20;
							if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
								SendClientMessage( playerid, COLOR_RED, "Sorry, all of our cars are in use." );
						}
					}
					else
					{
						SetPlayerInterior( playerid, 0 );
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						//SetVehiclePos( vehicleid, gSchool_Checkpoints[0][0][0], gSchool_Checkpoints[0][0][1], gSchool_Checkpoints[0][0][2] );
						SetPlayerRaceCheckpoint( playerid, 0, gSchool_Checkpoints[0][1][0], gSchool_Checkpoints[0][1][1], gSchool_Checkpoints[0][1][2], gSchool_Checkpoints[0][2][0], gSchool_Checkpoints[0][2][1], gSchool_Checkpoints[0][2][2], gSchool_Checkpoints[0][1][3] );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_CAR );
						gSchool_PlayerFlags[playerid] &= ~SCHOOL_PLAYER_FLAG_ATCARSCHOOL;
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL )
				{
					new vehicleid;
					vehicleid = g_pSchool_Vehicles[3] & VEHICLE_FLAG_FIRST;
					if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
					{
						vehicleid = (g_pSchool_Vehicles[3] & VEHICLE_FLAG_SECOND)>>10;
						if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
						{
							vehicleid = (g_pSchool_Vehicles[3] & VEHICLE_FLAG_THIRD)>>20;
							if( Vehicle_GetDriver( vehicleid ) != INVALID_PLAYER_ID )
								SendClientMessage( playerid, COLOR_RED, "Sorry, all of our bikes are in use." );
						}
					}
					else
					{
						SetPlayerInterior( playerid, 0 );
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						//SetVehiclePos( vehicleid, gSchool_Checkpoints[1][0][0], gSchool_Checkpoints[1][0][1], gSchool_Checkpoints[1][0][2] );
						SetPlayerRaceCheckpoint( playerid, 0, gSchool_Checkpoints[1][1][0], gSchool_Checkpoints[1][1][1], gSchool_Checkpoints[1][1][2], gSchool_Checkpoints[1][2][0], gSchool_Checkpoints[1][2][1], gSchool_Checkpoints[1][2][2], gSchool_Checkpoints[1][1][3] );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_BIKE );
						gSchool_PlayerFlags[playerid] &= ~SCHOOL_PLAYER_FLAG_ATBIKESCHOOL;
					}
				}				
			}
			
			case 1:
			{
				if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANBOATLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_BOATLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANFLYLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_FLYLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANCARLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_CARLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANBIKELIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_BIKELICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
			}
		}
	}
	return 1;
}



stock GetVehicleType(vehicleid) // Pixels^
{
	new type;
// ================== CARS =======
	switch(GetVehicleModel(vehicleid))
	{
		case
		416,   //ambulan  -  car
		445,   //admiral  -  car
		602,   //alpha  -  car
		485,   //baggage  -  car
		568,   //bandito  -  car
		429,   //banshee  -  car
		499,   //benson  -  car
		424,   //bfinject,   //car
		536,   //blade  -  car
		496,   //blistac  -  car
		504,   //bloodra  -  car
		422,   //bobcat  -  car
		609,   //boxburg  -  car
		498,   //boxville,   //car
		401,   //bravura  -  car
		575,   //broadway,   //car
		518,   //buccanee,   //car
		402,   //buffalo  -  car
		541,   //bullet  -  car
		482,   //burrito  -  car
		431,   //bus  -  car
		438,   //cabbie  -  car
		457,   //caddy  -  car
		527,   //cadrona  -  car
		483,   //camper  -  car
		524,   //cement  -  car
		415,   //cheetah  -  car
		542,   //clover  -  car
		589,   //club  -  car
		480,   //comet  -  car
		596,   //copcarla,   //car
		599,   //copcarru,   //car
		597,   //copcarsf,   //car
		598,   //copcarvg,   //car
		578,   //dft30  -  car
		486,   //dozer  -  car
		507,   //elegant  -  car
		562,   //elegy  -  car
		585,   //emperor  -  car
		427,   //enforcer,   //car
		419,   //esperant,   //car
		587,   //euros  -  car
		490,   //fbiranch,   //car
		528,   //fbitruck,   //car
		533,   //feltzer  -  car
		544,   //firela  -  car
		407,   //firetruk,   //car
		565,   //flash  -  car
		455,   //flatbed  -  car
		530,   //forklift,   //car
		526,   //fortune  -  car
		466,   //glendale,   //car
		604,   //glenshit,   //car
		492,   //greenwoo,   //car
		474,   //hermes  -  car
		434,   //hotknife,   //car
		502,   //hotrina  -  car
		503,   //hotrinb  -  car
		494,   //hotring  -  car
		579,   //huntley  -  car
		545,   //hustler  -  car
		411,   //infernus,   //car
		546,   //intruder,   //car
		559,   //jester  -  car
		508,   //journey  -  car
		400,   //landstal,   //car
		403,   //linerun  -  car
		517,   //majestic,   //car
		410,   //manana  -  car
		551,   //merit  -  car
		500,   //mesa  -  car
		418,   //moonbeam,   //car
		572,   //mower  -  car
		423,   //mrwhoop  -  car
		516,   //nebula  -  car
		582,   //newsvan  -  car
		467,   //oceanic  -  car
		404,   //peren  -  car
		514,   //petro  -  car
		603,   //phoenix  -  car
		600,   //picador  -  car
		413,   //pony  -  car
		426,   //premier  -  car
		436,   //previon  -  car
		547,   //primo  -  car
		489,   //rancher  -  car
		479,   //regina  -  car
		534,   //remingtn,   //car
		505,   //rnchlure,   //car
		442,   //romero  -  car
		440,   //rumpo  -  car
		475,   //sabre  -  car
		543,   //sadler  -  car
		605,   //sadlshit,   //car
		495,   //sandking,   //car
		567,   //savanna  -  car
		428,   //securica,   //car
		405,   //sentinel,   //car
		535,   //slamvan  -  car
		458,   //solair  -  car
		580,   //stafford,   //car
		439,   //stallion,   //car
		561,   //stratum  -  car
		409,   //stretch  -  car
		560,   //sultan  -  car
		550,   //sunrise  -  car
		506,   //supergt  -  car
		601,   //swatvan  -  car
		574,   //sweeper  -  car
		566,   //tahoma  -  car
		549,   //tampa  -  car
		420,   //taxi  -  car
		459,   //topfun  -  car
		576,   //tornado  -  car
		583,   //tug  -  car
		451,   //turismo  -  car
		558,   //uranus  -  car
		552,   //utility  -  car
		540,   //vincent  -  car
		491,   //virgo  -  car
		412,   //voodoo  -  car
		478,   //walton  -  car
		421,   //washing  -  car
		529,   //willard  -  car
		555,   //windsor  -  car
		456,   //yankee  -  car
		554,   //yosemite,   //car
		477   //zr3	50  -  car
		: type = VTYPE_CAR;

	// ================== MOTORBIKES =======
		case
		581,   //bf400  -  bike
		523,   //copbike  -  bike
		462,   //faggio  -  bike
		521,   //fcr900  -  bike
		463,   //freeway  -  bike
		522,   //nrg500  -  bike
		461,   //pcj600  -  bike
		448,   //pizzaboy,   //bike
		468,   //sanchez  -  bike
		586,   //wayfarer,   //bike
		471   //quad  -  quad
		: type = VTYPE_MOTORBIKE;
		
    // ================== BIKES =======
		case
		509,   //bike  -  bmx
		481,   //bmx  -  bmx
		510   //mtbike  -  bmx
		: type = VTYPE_BIKE;

	// ================== SEA =======
		case
		472,   //coastg  -  boat
		473,   //dinghy  -  boat
		493,   //jetmax  -  boat
		595,   //launch  -  boat
		484,   //marquis  -  boat
		430,   //predator,   //boat
		453,   //reefer  -  boat
		452,   //speeder  -  boat
		446,   //squalo  -  boat
		454   //tropic  -  boat
		: type = VTYPE_SEA;

	// ================== AIR =======
		case
		548,   //cargobob,   //heli
		425,   //hunter  -  heli
		417,   //leviathn,   //heli
		487,   //maverick,   //heli
		497,   //polmav  -  heli
		563,   //raindanc,   //heli
		501,   //rcgoblin,   //heli
		465,   //rcraider,   //heli
		447,   //seaspar  -  heli
		469,   //sparrow  -  heli
		488,   //vcnmav  -  heli
		592,   //androm  -  plane
		577,   //at	400  -  plane
		511,   //beagle  -  plane
		512,   //cropdust,   //plane
		593,   //dodo  -  plane
		520,   //hydra  -  plane
		553,   //nevada  -  plane
		464,   //rcbaron  -  plane
		476,   //rustler  -  plane
		519,   //shamal  -  plane
		460,   //skimmer  -  plane
		513,   //stunt  -  plane
		539   //vortex  -  plane
		: type = VTYPE_AIR;

	// ================== HEAVY =======
		case
		588,   //hotdog  -  car
		437,   //coach  -  car
		532,   //combine  -  car
		433,   //barracks,   //car
		414,   //mule  -  car
		443,   //packer  -  car
		470,   //patriot  -  car
		432,   //rhino  -  car
		525,   //towtruck,   //car
		531,   //tractor  -  car
		408,   //trash  -  car
		406,   //dumper  -  mtruck
		573,   //duneride,   //mtruck
		444,   //monster  -  mtruck
		556,   //monstera,   //mtruck
		557,   //monsterb,   //mtruck
		435,   //artict1  -  trailer
		450,   //artict2  -  trailer
		591,   //artict3  -  trailer
		606,   //bagboxa  -  trailer
		607,   //bagboxb  -  trailer
		610,   //farmtr1  -  trailer
		584,   //petrotr  -  trailer
		608,   //tugstair,   //trailer
		611,   //utiltr1  -  trailer
		590,   //freibox  -  train
		569,   //freiflat,   //train
		537,   //freight  -  train
		538,   //streak  -  train
		570,   //streakc  -  train
		449   //tram  -  train
		: type = VTYPE_HEAVY;

		// ================== MISC =======
		case
		441,   //rcbandit,   //misc
		594,   //rccam  -  misc
		564,   //rctiger  -  misc
		515,   //rdtrain  -  misc
		571   //kart  -  misc
		: type = VTYPE_MISC;
	}
	return type;
}

stock NeedLicense( modelid )
{
	switch( modelid ) {
		case 435, 441, 449, 450, 464, 465, 481, 501, 509, 510, 537, 538, 539, 564, 569, 570, 571, 572, 584, 590, 591, 594, 606, 607, 608, 610, 611: return 0;
	}
	return 1;
}

/*#include <a_samp>


new const Float:gSchool_Checkpoints[4][12][3] = //480byte
{
	{ // car
		{-2044.831665, -84.298553, 34.891147},
		{-2005.060913, -57.529224, 34.892040},
		{-2003.855102, 167.650634, 27.266208},
		{-2003.289184, 488.192657, 34.742710},
		{-2369.981445, 507.527465, 29.065008},
		{-2367.304199, 1068.211547, 55.305191},
		{-1888.020263, 1059.366943, 45.023960},
		{-1829.159057, 514.610412, 30.975446},
		{-1840.521728, 383.049926, 16.771482},
		{-1922.785522, -187.752853, 37.969299},
		{-2026.101074, -318.596649, 34.963607},
		{-2019.928710, -96.112792, 34.891124}
	},

	{ // bike
		{1171.262451, 1370.219848, 10.391620},
		{1006.916320, 1528.514282, 10.240498},
		{1030.855590, 1952.846313, 10.237700},
		{1121.523925, 2052.795898, 10.237578},
		{1524.717773, 2058.253906, 10.362090},
		{1670.386962, 2273.056884, 10.237950},
		{2108.463623, 2281.128417, 10.244203},
		{2032.472290, 1713.313110, 10.235921},
		{1788.867553, 1420.220703, 6.307698},
		{1789.417114, 863.941284, 10.212225},
		{1415.558837, 849.307739, 6.378320},
		{1218.364379, 1265.752075, 6.277549},
		{1175.613891, 1371.301757, 10.388628} My system supports only 12 checkpoints
	},

	{ // boat
		{-2146.997558, 2428.942138, -0.089766},
		{-1988.861694, 2160.382324, 0.229864},
		{-1532.871215, 1526.836059, -0.008878},
		{-1528.641723, 1344.618164, -0.133019},
		{-2233.000000, 1549.306152, -0.206533},
		{-2654.497802, 1613.182250, -0.143991},
		{-2939.801025, 1609.459228, 0.398771},
		{-3045.286865, 2008.724365, 0.988168},
		{-2684.370849, 2152.355224, -0.104622},
		{-2214.705566, 2244.005126, 0.294517},
		{-2237.232910, 2393.193115, -0.071032},
		{0.0, 0.0, 0.0} // One more checkpoint needed
	},

	{ // fly
		{383.262115, 2507.501708, 16.962657},
		{71.122306, 2497.119873, 30.762842},
		{-297.224090, 2420.688964, 87.799217},
		{-355.184509, 2112.731445, 134.605667},
		{-382.305267, 1588.746093, 90.777839},
		{-50.976974, 1488.350341, 37.895282,},
		{-128.558074, 1821.145751, 57.653831},
		{-267.346954, 1867.649414, 57.647132},
		{-555.859252, 2447.520263, 104.659568},
		{-183.767349, 2637.542480, 94.358642},
		{211.729034, 2521.661132, 30.813814},
		{424.360687, 2522.456298, 16.947921}
	}
};


#define COLOR_RED (0xFF0000FF)
#define COLOR_GREEN (0x009900FF)

#define SCHOOL_CHECKPOINT_SIZE (5.0)
#define SCHOOL_MAXIMUM_DAMAGE (100.0) // 10%

// You have to fill these coordinates
#define SCHOOL_CAR_POSX (0.0)
#define SCHOOL_CAR_POSY (0.0)
#define SCHOOL_CAR_POSZ (0.0)
#define SCHOOL_FLY_POSX (0.0)
#define SCHOOL_FLY_POSY (0.0)
#define SCHOOL_FLY_POSZ (0.0)
#define SCHOOL_BOAT_POSX (0.0)
#define SCHOOL_BOAT_POSY (0.0)
#define SCHOOL_BOAT_POSZ (0.0)
#define SCHOOL_BIKE_POSX (0.0)
#define SCHOOL_BIKE_POSY (0.0)
#define SCHOOL_BIKE_POSZ (0.0)

#define SCHOOL_PLAYER_FLAG_CHECKPOINT (1<<0+1<<1+1<<2+1<<3)
#define SCHOOL_PLAYER_FLAG_CARLICENSE (1<<4)
#define SCHOOL_PLAYER_FLAG_BIKELICENSE (1<<5)
#define SCHOOL_PLAYER_FLAG_FLYLICENSE (1<<6)
#define SCHOOL_PLAYER_FLAG_BOATLICENSE (1<<7)
#define SCHOOL_PLAYER_FLAG_CANCARLIC (1<<8)
#define SCHOOL_PLAYER_FLAG_CANBIKELIC (1<<9)
#define SCHOOL_PLAYER_FLAG_CANFLYLIC (1<<10)
#define SCHOOL_PLAYER_FLAG_CANBOATLIC (1<<11)
#define SCHOOL_PLAYER_FLAG_TEST (1<<12+1<<13+1<<14)
#define SCHOOL_PLAYER_FLAG_ATCARSCHOOL (1<<15)
#define SCHOOL_PLAYER_FLAG_ATBIKESCHOOL (1<<16)
#define SCHOOL_PLAYER_FLAG_ATFLYSCHOOL (1<<17)
#define SCHOOL_PLAYER_FLAG_ATBOATSCHOOL (1<<18)

#define SCHOOL_TEST_ID_NONE (0)
#define SCHOOL_TEST_ID_CAR (1)
#define SCHOOL_TEST_ID_BIKE (2)
#define SCHOOL_TEST_ID_FLY (3)
#define SCHOOL_TEST_ID_BOAT (4)

// In ticks
#define SCHOOL_TIME_CAR (60000)
#define SCHOOL_TIME_BOAT (60000)
#define SCHOOL_TIME_BIKE (60000)
#define SCHOOL_TIME_FLY (60000)


#define Player_SetCheckpoint(%1,%2) (gSchool_PlayerFlags[(%1)]&=~SCHOOL_PLAYER_FLAG_CHECKPOINT,gSchool_PlayerFlags[(%1)]|=(%2)&SCHOOL_PLAYER_FLAG_CHECKPOINT)
#define Player_GetCheckpoint(%1) (gSchool_PlayerFlags[(%1)]&SCHOOL_PLAYER_FLAG_CHECKPOINT)

#define Player_SetTestID(%1,%2) (gSchool_PlayerFlags[(%1)]&=~SCHOOL_PLAYER_FLAG_TEST,gSchool_PlayerFlags[(%1)]|=((%2)<<12)&SCHOOL_PLAYER_FLAG_TEST)
#define Player_GetTestID(%1) ((gSchool_PlayerFlags[(%1)]&SCHOOL_PLAYER_FLAG_TEST)>>12)


// Total of 2100bytes allocated at the start
new Menu:g_pSchool_Menu = Menu:INVALID_MENU; //4byte
new gSchool_PlayerFlags[MAX_PLAYERS]; //800byte
new gSchool_PlayerTimes[MAX_PLAYERS]; //800byte
new g_pSchool_Vehicles[4]; //16byte


forward School_Loop();


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
main()
{
	SetGameModeText( "LICENSE SYSTEM 0.0.4" );
	AddPlayerClass( 102, -2050.0, -97.054222, 35.882465, 90.0, 0, 0, 0, 0, 0, 0 ); // Just for testing

	for( new idx=0; idx<MAX_PLAYERS; idx++ ){
		gSchool_PlayerFlags[idx] = 0;
		gSchool_PlayerTimes[idx] = 0;
	}
	
	// Fill the IDs
	
	// CAR
	g_pSchool_Vehicles[0] |= CreateVehicle( 0, -2050.0, -97.054222, 34.882465, 0.3, -1, -1, 10 ) & (1<<10);
	g_pSchool_Vehicles[0] |= CreateVehicle( 0, -2046.0, -97.054222, 34.883880, 0.3, -1, -1, 10 ) & (1<<20);
	g_pSchool_Vehicles[0] |= CreateVehicle( 0, -2042.0, -97.054222, 34.880268, 0.3, -1, -1, 10 ) & (1<<30);

	// BOAT
	g_pSchool_Vehicles[1] |= CreateVehicle( 0, -2222.715576, 2398.058105, -0.099849, 39.568969, -1, -1, 10 ) & (1<<10);
	g_pSchool_Vehicles[1] |= CreateVehicle( 0, -2232.352539, 2393.290771, -0.116131, 39.568969, -1, -1, 10 ) & (1<<20);
	g_pSchool_Vehicles[1] |= CreateVehicle( 0, -2209.502929, 2410.615234, -0.087562, 39.568969, -1, -1, 10 ) & (1<<30);

	// AIR
	g_pSchool_Vehicles[2] |= CreateVehicle( 0, 352.946777, 2541.224609, 17.185791, 178.867675, -1, -1, 10 ) & (1<<10);
	g_pSchool_Vehicles[2] |= CreateVehicle( 0, 366.250122, 2540.902587, 17.067834, 179.798858, -1, -1, 10 ) & (1<<20);
	g_pSchool_Vehicles[2] |= CreateVehicle( 0, 380.827667, 2540.940185, 16.998163, 180.541809, -1, -1, 10 ) & (1<<30);

	// BIKE
	g_pSchool_Vehicles[3] |= CreateVehicle( 0, 1175.6, 1368.0, 10.393104, 87.313140, -1, -1, 10 ) & (1<<10);
	g_pSchool_Vehicles[3] |= CreateVehicle( 0, 1175.6, 1366.0, 10.381062, 89.579513, -1, -1, 10 ) & (1<<20);
	g_pSchool_Vehicles[3] |= CreateVehicle( 0, 1175.6, 1370.0, 10.380723, 88.615119, -1, -1, 10 ) & (1<<30);

	g_pSchool_Menu = CreateMenu( "Welcome to the Test", 2, 200.0, 100.0, 150.0, 150.0 );
	AddMenuItem( g_pSchool_Menu, 0, "Take Test" );
	AddMenuItem( g_pSchool_Menu, 0, "Receive License" );
	
	SetTimer( "School_Loop", 1000, true );
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
public OnPlayerDisconnect( playerid, reason )
{
	gSchool_PlayerFlags[playerid] = 0;
	gSchool_PlayerTimes[playerid] = 0;
	return 1; 
}


stock bool:Player_IsInPointRange( playerid, Float:x, Float:y, Float:z, Float:r )
{
	new Float:X,
		Float:Y,
		Float:Z;
		
	GetPlayerPos( playerid, X, Y, Z );

	X -= x;
	Y -= y;
	Z -= z;
	
	return (( X * X + Y * Y + Z * Z ) < ( r * r ));
}


public OnPlayerStateChange( playerid, newstate, oldstate )
{
	if( newstate == 1 && Player_GetTestID( playerid ) != SCHOOL_TEST_ID_NONE )
	{
		DisablePlayerCheckpoint( playerid );
		Player_SetCheckpoint( playerid, 0 );
		Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );
	}
	return 1;
}

public School_Loop()
{
	for( new i=0; i<MAX_PLAYERS; i++ )
	{
		if( IsPlayerConnected( i ) && Player_GetTestID(i) == SCHOOL_TEST_ID_NONE )
		{
			// CAR
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_CARLICENSE) && Player_IsInPointRange( i, SCHOOL_CAR_POSX, SCHOOL_CAR_POSY, SCHOOL_CAR_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_CAR_POSX, SCHOOL_CAR_POSY, SCHOOL_CAR_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATCARSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATCARSCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// BIKE
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_BIKELICENSE) && Player_IsInPointRange( i, SCHOOL_BIKE_POSX, SCHOOL_BIKE_POSY, SCHOOL_BIKE_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_BIKE_POSX, SCHOOL_BIKE_POSY, SCHOOL_BIKE_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATBIKESCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATBIKESCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// AIR
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_FLYLICENSE) && Player_IsInPointRange( i, SCHOOL_FLY_POSX, SCHOOL_FLY_POSY, SCHOOL_FLY_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_FLY_POSX, SCHOOL_FLY_POSY, SCHOOL_FLY_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATFLYSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATFLYSCHOOL;
				DisablePlayerCheckpoint( i );
			}
			
			// SEA
			if( !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL) && !(gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_BOATLICENSE) && Player_IsInPointRange( i, SCHOOL_BOAT_POSX, SCHOOL_BOAT_POSY, SCHOOL_BOAT_POSZ, 10.0 ) ){
				SetPlayerCheckpoint( i, SCHOOL_BOAT_POSX, SCHOOL_BOAT_POSY, SCHOOL_BOAT_POSZ, 2.0 );
				gSchool_PlayerFlags[i] |= SCHOOL_PLAYER_FLAG_ATBOATSCHOOL;
			}
			else if( gSchool_PlayerFlags[i] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL ) {
				gSchool_PlayerFlags[i] &= ~SCHOOL_PLAYER_FLAG_ATBOATSCHOOL;
				DisablePlayerCheckpoint( i );
			}
		}
	}
}


public OnPlayerExitedMenu( playerid )
{
	TogglePlayerControllable( playerid, true );
	return 1;
}


public OnPlayerEnterCheckpoint( playerid )
{
	new exam = Player_GetTestID( playerid );
	if( exam != SCHOOL_TEST_ID_NONE )
	{
		new check = Player_GetCheckpoint( playerid );
		new vehicleid = GetPlayerVehicleID( playerid );
		new Float:hp;

		GetVehicleHealth( vehicleid, hp );
		DisablePlayerCheckpoint( playerid );
	
		if( hp <= (1000-SCHOOL_MAXIMUM_DAMAGE) )
		{
			SendClientMessage( playerid, COLOR_RED, "Test Failed: You have damaged your vehicle!" );
			Player_SetCheckpoint( playerid, 0 );
			Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );
		}
		else
		{
			if( (check+2) <= 10 )
			{
				if( check == 0 )
				{
					gSchool_PlayerTimes[playerid] = GetTickCount();
				}
			
				check++;
				SetPlayerCheckpoint( playerid, gSchool_Checkpoints[exam][check][0], gSchool_Checkpoints[exam][check][1], gSchool_Checkpoints[exam][check][2], SCHOOL_CHECKPOINT_SIZE );
				Player_SetCheckpoint( playerid, check );
			}
			else
			{
				vehicleid = 0;
				switch( exam )
				{
					case SCHOOL_TEST_ID_CAR: if( GetTickCount() - gSchool_PlayerTimes[playerid] < SCHOOL_TIME_CAR ) vehicleid = 1;
					case SCHOOL_TEST_ID_FLY: if( GetTickCount() - gSchool_PlayerTimes[playerid] < SCHOOL_TIME_FLY ) vehicleid = 1;
					case SCHOOL_TEST_ID_BIKE: if( GetTickCount() - gSchool_PlayerTimes[playerid] < SCHOOL_TIME_BIKE ) vehicleid = 1;
					case SCHOOL_TEST_ID_BOAT: if( GetTickCount() - gSchool_PlayerTimes[playerid] < SCHOOL_TIME_BOAT ) vehicleid = 1;
				}
				
				if( vehicleid )
				{
					gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_CANCARLIC << (exam-1);
					SendClientMessage( playerid, COLOR_GREEN, "Congratulations! Go and get your license at the school!" );
				}
				else
				{
					SendClientMessage( playerid, COLOR_RED, "Test Failed: Out of time!" );
				}
				Player_SetCheckpoint( playerid, 0 );
				Player_SetTestID( playerid, SCHOOL_TEST_ID_NONE );
			}
		}
	}
	
	if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL || gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL ||
		gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL || gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
	{
		ShowMenuForPlayer( g_pSchool_Menu, playerid );
		TogglePlayerControllable( playerid, false );
	}
	return 1;
}

stock Vehicle_GetDriver( vehicleid )
{
	for( new x=0; x<MAX_PLAYERS; x++ ) if( IsPlayerConnected(x) && GetPlayerVehicleID(x) == vehicleid && GetPlayerState(x) == 2 ) return x;
	return INVALID_PLAYER_ID;
}

public OnPlayerSelectedMenuRow( playerid, row )
{
	if( GetPlayerMenu( playerid ) == g_pSchool_Menu )
	{
		switch( row )
		{
			case 0:
			{
				if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL )
				{
					new i, vehicleid;
					for( i=0; i<3; i++ ) if( Vehicle_GetDriver( ( vehicleid = g_pSchool_Vehicles[1] & (1>>((i+1)*10)) ) ) != INVALID_PLAYER_ID ) break;
					if( i == 3 )
					{
						SendClientMessage( playerid, COLOR_RED, "Sorry, all of our boats are in use." );
					}
					else
					{
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						SetVehiclePos( vehicleid, gSchool_Checkpoints[2][0][0], gSchool_Checkpoints[2][0][1], gSchool_Checkpoints[2][0][2] );
						SetPlayerCheckpoint( playerid, gSchool_Checkpoints[2][1][0], gSchool_Checkpoints[2][1][1], gSchool_Checkpoints[2][1][2], SCHOOL_CHECKPOINT_SIZE );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_BOAT );
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL )
				{
					new i, vehicleid;
					for( i=0; i<3; i++ )
					{
						vehicleid =
						if( Vehicle_GetDriver( ( vehicleid = g_pSchool_Vehicles[2] & (1>>((i+1)*10)) ) ) != INVALID_PLAYER_ID ) break;
					if( i == 3 )
					{
						SendClientMessage( playerid, COLOR_RED, "Sorry, all of our planes are in use." );
					}
					else
					{
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						SetVehiclePos( vehicleid, gSchool_Checkpoints[3][0][0], gSchool_Checkpoints[3][0][1], gSchool_Checkpoints[3][0][2] );
						SetPlayerCheckpoint( playerid, gSchool_Checkpoints[3][1][0], gSchool_Checkpoints[3][1][1], gSchool_Checkpoints[3][1][2], SCHOOL_CHECKPOINT_SIZE );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_FLY );
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
				{
					new i, vehicleid;
					for( i=0; i<3; i++ ) if( Vehicle_GetDriver( ( vehicleid = g_pSchool_Vehicles[0] & (1>>((i+1)*10)) ) ) != INVALID_PLAYER_ID ) break;
					if( i == 3 )
					{
						SendClientMessage( playerid, COLOR_RED, "Sorry, all of our cars are in use." );
					}
					else
					{
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						SetVehiclePos( vehicleid, gSchool_Checkpoints[0][0][0], gSchool_Checkpoints[0][0][1], gSchool_Checkpoints[0][0][2] );
						SetPlayerCheckpoint( playerid, gSchool_Checkpoints[0][1][0], gSchool_Checkpoints[0][1][1], gSchool_Checkpoints[0][1][2], SCHOOL_CHECKPOINT_SIZE );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_CAR );
					}
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL )
				{
					new i, vehicleid;
					for( i=0; i<3; i++ ) if( Vehicle_GetDriver( ( vehicleid = g_pSchool_Vehicles[3] & (1>>((i+1)*10)) ) ) != INVALID_PLAYER_ID ) break;
					if( i == 3 )
					{
						SendClientMessage( playerid, COLOR_RED, "Sorry, all of our bikes are in use." );
					}
					else
					{
						PutPlayerInVehicle( playerid, vehicleid, 0 );
						SetVehiclePos( vehicleid, gSchool_Checkpoints[1][0][0], gSchool_Checkpoints[1][0][1], gSchool_Checkpoints[1][0][2] );
						SetPlayerCheckpoint( playerid, gSchool_Checkpoints[1][1][0], gSchool_Checkpoints[1][1][1], gSchool_Checkpoints[1][1][2], SCHOOL_CHECKPOINT_SIZE );
						Player_SetCheckpoint( playerid, 1 );
						gSchool_PlayerTimes[playerid] = GetTickCount();
						Player_SetTestID( playerid, SCHOOL_TEST_ID_BIKE );
					}
				}				
			}
			
			case 1:
			{
				if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBOATSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANBOATLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_BOATLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATFLYSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANFLYLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_FLYLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATCARSCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANCARLIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_CARLICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
				
				else if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_ATBIKESCHOOL )
				{
					if( gSchool_PlayerFlags[playerid] & SCHOOL_PLAYER_FLAG_CANBIKELIC )
					{
						gSchool_PlayerFlags[playerid] |= SCHOOL_PLAYER_FLAG_BIKELICENSE;
						SendClientMessage( playerid, COLOR_GREEN, "Congratulations for your new license!" );
					}
					else SendClientMessage( playerid, COLOR_RED, "You have to pass the test!" );
				}
			}
		}
	}
	return 1;
}*/
